import request from '@/utils/request'
import { transformQueryCondition } from '@/utils'
import qs from 'qs'
// 插入
export function insertItem(data) {
  return request({
    url: '/uums/SysRolePrivilege',
    method: 'POST',
    data: data
  })
}

// 批量插入
export function batchInsertItem(data) {
  return request({
    url: '/uums/SysRolePrivilege/batchByRoleId/?roleId=' + data.roleId,
    method: 'POST',
    data: data.insertArr
  })
}

// 根据父菜单批量插入子菜单
export function batchInsertItemByParent(data) {
  return request({
    url: '/uums/SysRolePrivilege/batchByRoleIdAndParentId/?roleId=' + data.roleId,
    method: 'POST',
    data: data.insertArr
  })
}

// 批量插入
export function batchCopyRoles(data) {
  return request({
    url: '/uums/SysUserRole/copyRolebatch',
    method: 'POST',
    data: data
  })
}

// 批量插入
export function batchInsertItemUser(data) {
  return request({
    url: '/uums/SysUserRole/batch',
    method: 'POST',
    data: data
  })
}

// 复合检索
export function compositeSelect(query) {
  const searchCon = transformQueryCondition(query)
  return request({
    url: '/uums/SysRolePrivilege/compositeSelect',
    method: 'POST',
    data: searchCon
  })
}

// 求件
export function countSelect(query) {
  const searchCon = transformQueryCondition(query)
  return request({
    url: '/uums/SysRolePrivilege/count',
    method: 'POST',
    data: searchCon
  })
}

// 强制删除
export function forceDeleteItem(data) {
  return request({
    url: '/uums/SysRolePrivilege/force',
    method: 'DELETE',
    data: data
  })
}

// 批量强制删除
export function batchDeleteItem(data) {
  return request({
    url: '/uums/SysRolePrivilege/force/batch',
    method: 'DELETE',
    data: data
  })
}

// 检索
export function select(query) {
  const searchCon = transformQueryCondition(query)
  return request({
    url: '/uums/SysRolePrivilege/select',
    method: 'POST',
    data: searchCon
  })
}

// 更新
export function updateItem(id, data) {
  return request({
    url: '/uums/SysRolePrivilege/' + id,
    method: 'PUT',
    data: data
  })
}

// 检索
export function selectSysSubsys(query) {
  const searchCon = transformQueryCondition(query)
  return request({
    url: '/uums/SysSubsys/select',
    method: 'POST',
    data: searchCon
  })
}
// 检索
export function SysOrgInfo(query) {
  return request({
    url: '/uums/SysUserRole/batch',
    method: 'POST',
    data: query
  })
}

// 删除
export function deleteHandle(query) {
  return request({
    url: '/uums/SysUserRole/force/batch',
    method: 'DELETE',
    data: query
  })
}

// 检索
export function selectMenuTree(data) {
  const searchCon = qs.stringify(data)
  return request({
    url: '/uums/SysPrivilegeInfo/role/tree',
    method: 'POST',
    data: searchCon
  })
}

// 检索
export function selectMenuTreeByUserId(data) {
  const searchCon = qs.stringify(data)
  return request({
    url: '/uums/SysPrivilegeInfo/role/privilege/tree?',
    method: 'POST',
    data: searchCon
  })
}

// 动态菜单
export function getUserMenu(data) {
  const searchCon = qs.stringify(data)
  return request({
    url: '/uums/common/menu/getUserMenu?',
    method: 'POST',
    data: searchCon
  })
}

// 查询已选择的权限
export function hasSelectPri(data) {
  const searchCon = transformQueryCondition(data)
  return request({
    url: '/uums/SysRolePrivilege/hasSelectPri?roleId=' + data.roleId,
    method: 'POST',
    data: searchCon
  })
}
// 检索
export function treeById(data) {
  data.status = '0,1'
  const searchCon = qs.stringify(data)
  return request({
    url: '/uums/SysOrgInfo/treeById',
    method: 'POST',
    data: searchCon
  })
}
// 检索
export function selectExistUser(data) {
  const searchCon = transformQueryCondition(data)
  return request({
    url: '/uums/SysUserRole/selectExistUser/?roleId=' + data.roleId,
    method: 'POST',
    data: searchCon
  })
}
// 检索
export function selectNoExistUser(data) {
  let searchCon = transformQueryCondition(data)
  delete searchCon.userId
  return request({
    url: '/uums/SysUserRole/selectNoExistUser/?roleId=' + data.roleId + '&orgId=' + data.orgId,
    method: 'POST',
    data: searchCon
  })
}

// 检索未设置角色人员
export function userSelected(data) {
  let searchCon = transformQueryCondition(data)
  delete searchCon.userId
  return request({
    url: '/uums/SysUserRole/userSelected/?roleId=' + data.roleId + '&orgId=' + data.orgId + '&isExist='+data.isExist,
    method: 'POST',
    data: searchCon
  })
}

// 复合检索-系统角色与功能权限关系表
export function compositeSelectSysRolePrivilege(query) {
  const searchCon = transformQueryCondition(query)
  return request({
    url: '/uums/SysRolePrivilege/compositeSelect',
    method: 'POST',
    data: searchCon
  })
}

// 根据用户检索角色信息
export function SelectUserRole(query) {
  const searchCon = transformQueryCondition(query)
  // 兼职
  if (query.isPt) {
    return request({
      url: '/uums/SysUserRole/selectUserRole/?userId=' + query.userId +  '&orgId='+query.orgId + '&isExist=' + query.isExist + '&isPt=' + query.isPt,
      method: 'POST',
      data: searchCon
    })
  } else {
    return request({
      url: '/uums/SysUserRole/selectUserRole/?userId=' + query.userId + '&isExist=' + query.isExist,
      method: 'POST',
      data: searchCon
    })
  }
}

// 根据机构ID检索角色信息
export function SelectUserRoleByOrgId(query) {
  const searchCon = transformQueryCondition(query)
  console.log('query')
  console.log(query)
  // 兼职
  if (query.isPt) {
    return request({
      url: '/uums/SysUserRole/selectUserRole/?userId=' + query.userId + '&orgId='+query.orgId + '&isExist=' + query.isExist + '&isPt=' + query.isPt,
      method: 'POST',
      data: searchCon
    })
  } else {
    return request({
      url: '/uums/SysUserRole/selectUserRole/?userId=' + query.userId + '&orgId='+query.orgId + '&isExist=' + query.isExist,
      method: 'POST',
      data: searchCon
    })
  }
}

// 查询系统码表
export function sysCodeListByCodeType(query) {
  return request({
    url: uumsPrefix + '/FreeCertification/SysCodeCommon/getSysCodeList?codeType=' + query.codeType + '&codeStatus=' + query.codeStatus,
    method: 'POST',
    data: query
  })
}

